<script language="Javascript">
	function MiseForme(Controleur, Controle, ref, listnum) {
	var objControleur = document.getElementById(Controleur);
	var objControle = document.getElementById(Controle);
	var trust = false;
		if (ref==0){
			objControle.required = (objControleur.value==0)?false:true;
			trust = (objControleur.value==0)?"none":"block";
			objControle.style.display = trust;
			document.getElementById(Controle+"-label").style.display = trust;
			
			if(listnum == 'list1'){
				document.getElementById('lieu_mariage').style.display = trust;
				document.getElementById('date_fin_mariage').style.display = trust;
				document.getElementById('motif_fin_mariage').style.display = trust;

				document.getElementById('lieu_mariage-label').style.display = trust;
				document.getElementById('date_fin_mariage-label').style.display = trust;
				document.getElementById('motif_fin_mariage-label').style.display = trust;
			}
			if(listnum == 'list2'){
				document.getElementById('motif_liaison').style.display = trust;

				document.getElementById('motif_liaison-label').style.display = trust;
			}
		}
		if (ref==1){
			trust = (objControleur.value=="")?"none":"block";
			objControle.style.display = trust;
			document.getElementById(Controle+"-label").style.display = trust;
			document.getElementById('commentaire_photo').style.display = trust;
			document.getElementById('commentaire_photo-label').style.display = trust;
		}
		return true;
	}

	function professionChecker(){
		//document.getElementById('speacteur').disabled = (document.getElementById('profession-1').checked == true)?false:true;
		document.getElementById('speacteur').style.display = (document.getElementById('profession-1').checked == true)?"block":"none";
		document.getElementById('speacteur-label').style.display = (document.getElementById('profession-1').checked == true)?"block":"none";

		document.getElementById('spechanteur').style.display = (document.getElementById('profession-3').checked == true)?"block":"none";
		document.getElementById('spechanteur-label').style.display = (document.getElementById('profession-3').checked == true)?"block":"none";

		document.getElementById('spemannequin').style.display = (document.getElementById('profession-4').checked == true)?"block":"none";
		document.getElementById('spemannequin-label').style.display = (document.getElementById('profession-4').checked == true)?"block":"none";
	}

	function init(){
		var trust = "none";
		if(document.getElementById('photo').value == ""){
			document.getElementById('commentaire_photo').style.display = trust;
			document.getElementById('Sujet').style.display = trust;
			
			document.getElementById('commentaire_photo-label').style.display = trust;
			document.getElementById('Sujet-label').style.display = trust;
		}
		
		if(document.getElementById('mariage').value == 0){
			document.getElementById('date_mariage').style.display = trust;
			document.getElementById('lieu_mariage').style.display = trust;
			document.getElementById('date_fin_mariage').style.display = trust;
			document.getElementById('motif_fin_mariage').style.display = trust;
			
			document.getElementById('date_mariage-label').style.display = trust;
			document.getElementById('lieu_mariage-label').style.display = trust;
			document.getElementById('date_fin_mariage-label').style.display = trust;
			document.getElementById('motif_fin_mariage-label').style.display = trust;
		}
		if(document.getElementById('liaison').value == 0){
			document.getElementById('date_liaison').style.display = trust;
			document.getElementById('motif_liaison').style.display = trust;

			document.getElementById('date_liaison-label').style.display = trust;
			document.getElementById('motif_liaison-label').style.display = trust;
		}
		
		professionChecker();
	}
</script>

<?php
class Form_Ajoutervip extends Zend_Form{
	public function init(){
		$this->setMethod('post');
		$this->setName('ajoutervip');
		$this->setAttrib('enctype', 'multipart/form-data');
		
		$addPrenom = $this->createElement('text', 'prenom');
		$addPrenom	->setLabel("Prénom* : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(3,50))
						->addFilter('StringTrim')
						->setRequired(TRUE);
		$addNom = $this->createElement('text', 'nom');
		$addNom	->setLabel("Nom* : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(3,50))
						->addFilter('StringTrim')
						->setRequired(TRUE);
		$addSexe = new Zend_Form_Element_Select('sexe'); 
		$addSexe->setLabel('Sexe : ')
						->addMultiOption("M", "Masculin")
						->addMultiOption("F", "Feminin");
		$addDate = $this->createElement('text', 'date');
		$addDate	->setLabel("Date de naissance : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(10,10))
						->addFilter('StringTrim')
						->addValidator('date', false, array('dd/MM/yyyy'))
						->setRequired(FALSE)
						->setAttrib('placeholder', "JJ/MM/AAAA");
		$nationalites=VipsController::getAllNationnalitesAction();
		$addNationalite = new Zend_Form_Element_Select('nationalite');
		$addNationalite ->setLabel("Nationalite : ")
						->setRequired(TRUE);
		foreach($nationalites as $natio){
			$addNationalite ->addMultiOption( $natio->NATIONALITE_NUMERO, $natio->NATIONALITE_NOM);
		}
		$addCommentaire = new Zend_Form_Element_Textarea('commentaire');
		$addCommentaire ->setLabel('Commentaire : ')
						->addFilter('StripTags')
						->addFilter('StringTrim')
						->setAttrib('cols', '40')
						->setAttrib('rows', '4');				
		$addPhoto =new Zend_Form_Element_File('photo');
		$addPhoto->setLabel('Selectionner l\'image :')
        		->setDestination('./images/photos/')
				->setAttrib('onchange', "MiseForme('photo', 'Sujet', 1, 'list3');")
				->addValidator('Count', false, 1)
				->addValidator('Size', false, 10485760)
				->addValidator('Extension', false, 'jpg,png,gif');
		$addSujet = $this->createElement('text', 'Sujet');
		$addSujet->setLabel("Sujet : ")
				->addFilter('StripTags')
				->addValidator('StringLength', false, array(3,50))
				->addFilter('StringTrim')
				->setRequired(FALSE);
		$addCommentairePhoto = $this->createElement('text', 'commentaire_photo');
		$addCommentairePhoto->setLabel("Commentaire : ")
							->addFilter('StripTags')
							->addValidator('StringLength', false, array(3,200))
							->addFilter('StringTrim')
							->setRequired(FALSE);
							
		$addProfession = new Zend_Form_Element_MultiCheckbox('profession', array(
				    'multiOptions' => array(
				        '1' => 'acteur',
				        '2' => 'realisateur',
				        '3' => 'chanteur',
				        '4' => 'mannequin',
						'5' => 'couturier',
				    )
				));
		$addProfession	-> setLabel("Profession(s) : ")
						->setAttrib('onclick', "professionChecker();");
						
						
		$speacteur = $this->createElement('text', 'speacteur');
		$speacteur	->setLabel("Débuts d'acteur : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(10,10))
						->addFilter('StringTrim')
						->addValidator('date', false, array('dd/MM/yyyy'))
						->setRequired(FALSE)
						->setAttrib('placeholder', "JJ/MM/AAAA");
						
		$spechanteur = $this->createElement('text', 'spechanteur');
		$spechanteur	->setLabel("Spécialité de chanson : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(1,50))
						->addFilter('StringTrim')
						->setRequired(FALSE);
						
		$spemannequin = $this->createElement('text', 'spemannequin');
		$spemannequin	->setLabel("Taille (cm) : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(1,3))
						->addValidator('alnum')
						->setRequired(FALSE);
						
		$vips=VipsController::gatAllVipsAction();
		$addMariage = new Zend_Form_Element_Select('mariage');
		$addMariage ->setLabel("Mariage actuel : ")
						->setAttrib('onclick', "MiseForme('mariage', 'date_mariage', 0, 'list1');")
						->addMultiOption(0, "Selectionner le vip");
		foreach($vips as $vip){
			$addMariage ->addMultiOption( $vip->VIP_NUMERO, $vip->VIP_NOM." ".$vip->VIP_PRENOM);
		}
		
		$addDateMariage = $this->createElement('text', 'date_mariage');
		$addDateMariage	->setLabel("Date : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(10,10))
						->addFilter('StringTrim')
						->addValidator('date', false, array('dd/MM/yyyy'))
						->setRequired(FALSE)
						->setAttrib('placeholder', "JJ/MM/AAAA");
						
		$addLieuMariage = $this->createElement('text', 'lieu_mariage');
		$addLieuMariage	->setLabel("Lieu : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(3,50))
						->addFilter('StringTrim')
						->setRequired(FALSE);
		$addDateFinMariage = $this->createElement('text', 'date_fin_mariage');
		$addDateFinMariage	->setLabel("Date de fin du mariage: ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(10,10))
						->addFilter('StringTrim')
						->addValidator('date', false, array('dd/MM/yyyy'))
						->setRequired(FALSE)
						->setAttrib('placeholder', "JJ/MM/AAAA");
		$addMotifFinMariage = $this->createElement('text', 'motif_fin_mariage');
		$addMotifFinMariage	->setLabel("Motif : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(3,50))
						->addFilter('StringTrim')
						->setRequired(FALSE);
		$addLiaison = new Zend_Form_Element_Select('liaison');
		$addLiaison ->setLabel("Liaison actuel : ")
						->setAttrib('onclick', "MiseForme('liaison', 'date_liaison', 0, 'list2');")
						->addMultiOption(0, "Selectionner le vip");
		foreach($vips as $vip){
			$addLiaison ->addMultiOption( $vip->VIP_NUMERO, $vip->VIP_NOM." ".$vip->VIP_PRENOM);
		}
		$addDateLiaison = $this->createElement('text', 'date_liaison');
		$addDateLiaison	->setLabel("Date : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(10,10))
						->addFilter('StringTrim')
						->addValidator('date', false, array('dd/MM/yyyy'))
						->setRequired(FALSE)
						->setAttrib('placeholder', "JJ/MM/AAAA");
		$addMotifLiaison = $this->createElement('text', 'motif_liaison');
		$addMotifLiaison	->setLabel("Motif : ")
						->addFilter('StripTags')
						->addValidator('StringLength', false, array(3,50))
						->addFilter('StringTrim')
						->setRequired(FALSE);
						
		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setLabel('Ajouter');
		
		$this->addElements(array($addNom,$addPrenom,$addSexe,$addDate,$addNationalite,
								$addCommentaire,$addPhoto,$addSujet,$addCommentairePhoto,
								$addProfession,$speacteur, $spechanteur, $spemannequin,
								$addMariage,$addDateMariage,$addLieuMariage,$addDateFinMariage,
								$addMotifFinMariage,$addLiaison,$addDateLiaison,$addMotifLiaison,$submit));
		
		//On initialise
		?>
		<script language="Javascript">
			init();
		</script>
		<?php 					
								
		//On modifie les styles par default
		//$this->clearDecorators();
		
		$this->setElementDecorators(array('ViewHelper','Description','Errors',
                   array(array('data'=>'HtmlTag'), array('tag' => 'td')),
                   array('Label', array('tag' => 'td')),
                   array(array('row'=>'HtmlTag'),array('tag'=>'tr'))));
                   
        $addPhoto->setDecorators(
			    array(
			        'File',
			        'Errors',
			        array(array('data' => 'HtmlTag'), array('tag' => 'td')),
			        array('Label', array('tag' => 'th')),
			        array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
			    )
);
        
		$submit->setDecorators(array(
				'ViewHelper','Description','Errors', array(array('data'=>'HtmlTag'),
				array('tag' => 'td','colspan'=>'2','align'=>'left')),
				array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
       ));
       
		
		$this->setDecorators(array('FormElements', array(array('data'=>'HtmlTag'),array('tag'=>'table')),'Form'));
	}
}